<?php

namespace app\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Filesystem;
use think\facade\View;
require_once '../vendor/autoload.php';
use \TCPDF as TCPDF;
class show extends BaseController
{


  public function index(){  //初次混编
      $name="刘佩东";
      View::assign("name",$name);
     return View::fetch("test/test.html");
  }
   public function indexs(){  //携带参数
        $name="刘佩东";
        View::assign("name",$name);
        return View::fetch("test/lpd1.html");
    }
    public function shuzu(){  //shuzu携带参数
        $name="刘佩东";
        $age=18;
        View::assign([
            "name"=>$name,
            "age"=>$age
        ]);
        return View::fetch("test/lpd.html");
    }
    public function de(){  //shuzu携带参数
        $name="刘佩东";
        $age=18;

        return View::fetch("test/lpd.html",[
            "name"=>$name,
            "age"=>$age
        ]);
    }
    public function suoxie(){  //shuzu携带参数
        $name="刘佩东";
        $age=18;

        return View("test/lpd.html",[
            "name"=>$name,
            "age"=>$age
        ]);
    }
    public function guolv(){  //shuzu携带参数
     /*   $name = "刘佩东";
        $age = 18;*/
        View::assign([
            "name" => "1",
            "age" => "2"
        ]);
        return View("test/lpd2.html")->filter(function ($a){
            return $a;
        });
    }


    public function lpdfiles(){  //shuzu携带参数

        if ($this->request->isPost()){
            $file = $this->request->file("img");  //获取表单提交的文件上传对象
            $newFilename = "123".'.txt';  // 获取原始文件名并更改后缀为txt
            /* $savePath = Filesystem::disk("public")->putFileAs('topic', $file, $newFilename); */ // 将文件移动到指定目录并指定新的文件名
            $savePath = Filesystem::disk("public")->putFileAs('topic',$file, $newFilename);
            $path = $this->app->getRootPath();
            dump($savePath);
            dump($path);
        } else {
            return View("test/lpdfile.html");
        }

    }
    public function pdf()
    {
        $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8');
        $pdf->SetFont('dejavusans', '', 12);
        // 设置文档信息
        $pdf->SetCreator('Your Name');
        $pdf->SetAuthor('Your Name');
        $pdf->SetTitle('PDF Example');
        $pdf->SetSubject('Generating PDF in ThinkPHP');
        $pdf->SetKeywords('PDF, ThinkPHP');

        // 添加一页
        $pdf->AddPage();

        // 设置字体和字号
        $pdf->SetFont('stsongstdlight', '', 12);

        // 写入内容
        $pdf->Cell(0, 10, 'Hello, World!草拟吗', 0, 1, 'C');

        // 插入图片
        $imagePath = '../public/upload/lpd/20231127/e6aa6c113955bb8cfd1f99bc2851bf0d.png'; // 替换为你的图片路径
        $pdf->Image($imagePath, 10, 30, 50, 0, 'png');

        // 输出PDF文件
        $pdf->Output('lpd.pdf', 'D');
    }







}